/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.core.listener;

import org.eclipse.emf.common.notify.Adapter;
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.common.notify.Notifier;
import org.eclipse.ui.views.properties.tabbed.ISection;


/**
 * 
 */
public class PropertyViewListener implements Adapter {
	
	/**
	 * 
	 */
	private Notifier _target;
	
	/**
	 * 
	 */
	protected ISection section;

	
	/**
	 * 
	 * 
	 * @param section 
	 */
	public PropertyViewListener(ISection section){	
			this.section=section;
	}

	
	/**
	 * 
	 * 
	 * @param notification 
	 */
	public void notifyChanged(Notification notification) {
		//It is un usefull to refresh when we receive an Notification.ADD, 
		//it can raise null pointer Exception because the composite is not created
		if( notification.getEventType()!=Notification.REMOVING_ADAPTER
			&& notification.getEventType()!= Notification.ADD 
			&& notification.getEventType() != Notification.REMOVE){
		section.refresh();}
		
		
	}

	
	/**
	 * 
	 * 
	 * @return 
	 */
	public Notifier getTarget() {
		return this._target;
	}

	
	/**
	 * 
	 * 
	 * @param newTarget 
	 */
	public void setTarget(Notifier newTarget) {
		this._target = newTarget;
	}

	
	/**
	 * 
	 * 
	 * @param type 
	 * 
	 * @return 
	 */
	public boolean isAdapterForType(Object type) {
		return type.equals(section.getClass());
	}

}